package com.project.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.DisasterPrevention.EventBean;
import com.project.bean.ExpertConsultation.ConsultBean;
import com.project.mapper.IEventMapper;
import com.project.service.IEventService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;


@Service
@Transactional

public class IEventServiceImpl extends ServiceImpl<IEventMapper, EventBean>  implements IEventService {

    @Resource
    private IEventMapper eventMapper;
    @Override
    public IPage<EventBean> findCutEvent(int pagNo, int pageSize, String eventName, String eventStage, String regionName, LocalDate startDate, LocalDate endData) {

        Page<EventBean> page = new Page<>(pagNo,pageSize);

        QueryWrapper wrapper = new QueryWrapper();

        if (eventName != null){
            wrapper.like("event_name",eventName);
        }
        if (eventStage != null){
            wrapper.like("event_stage",eventStage);
        }
        if (regionName != null){
            wrapper.like("event_place",regionName);
        }
        if (startDate != null){
            wrapper.ge("event_day",startDate);
        }
        if (endData != null){
            wrapper.le("event_day",endData);
        }


        IPage<EventBean> page1 = this.baseMapper.selectPage(page,wrapper);

        return page1;
    }

    @Override
    public void addEvent(EventBean eventBean) {

        this.baseMapper.insert(eventBean);

    }

    @Override
    public EventBean findEvent(int eventId) {


        return eventMapper.findEvent(eventId);

    }

    @Override
    public void updateEvent(int eventId, String eventStage, String eventPrecept) {

        EventBean eventBean = new EventBean();

        eventBean.setEventId(eventId);

        eventBean.setEventStage(eventStage);
        eventBean.setEventPrecept(eventPrecept);

        this.baseMapper.updateById(eventBean);

    }

    @Override
    public List<EventBean> findAllEvent() {

        return this.baseMapper.selectList(null);

    }

    @Override
    public void updateEventStage(int eventId, String eventStage) {

        EventBean eventBean = new EventBean();
        eventBean.setEventId(eventId);
        eventBean.setEventStage(eventStage);

        this.baseMapper.updateById(eventBean);
    }

    @Override
    public void updateEventAdvice(int eventId, String eventAdvice) {

        EventBean eventBean = new EventBean();
        eventBean.setEventId(eventId);
        eventBean.setEventAdvice(eventAdvice);

        this.baseMapper.updateById(eventBean);

    }

    @Override
    public EventBean findConsult(int eventId) {

        return this.eventMapper.findConsult(eventId);
    }
}
